//
//  FIYYBaseEntity.m
//  Magpie
//
//  Created by 100TV protocal on 12-11-15.
//
//

#import "FIYYBaseEntity.h"
#import "FIStringHelper.h"

@implementation FIYYBaseEntity

-(id) init{
	if ((self=[super init])){
		attributeDic=[[NSMutableDictionary alloc] init];
	}
	return self;
}

-(void) dealloc{
	[attributeDic release];
	[super dealloc];
}

-(id) attributeForKey:(id)akey{
	return [attributeDic objectForKey:akey];
}

-(void) setAttribute:(id)aobj forKey:(id)akey{
	assert(akey!=nil);
	if(aobj==nil){
		[attributeDic removeObjectForKey:akey];
	}else{
		[attributeDic setObject:aobj forKey:akey];
	}
}

-(BOOL) hasError{
	BOOL ret=YES;
	NSString* result=[self attributeForKey:KEY_RESULT];
	if(result!=nil && [result isEqualToString:VALUE_RESULT_SUCCESS]){
		ret=NO;
	}
	return ret;
}

-(NSString *) description{
	NSAutoreleasePool* pool=[[NSAutoreleasePool alloc] init];
	NSString* ret=[NSString stringWithFormat:@"%@ {\n",[self class]];
	NSArray* keyArray=[attributeDic allKeys];
	for(id key in keyArray){
		ret=[ret stringByAppendingFormat:@"\t%@=%@,\n",key,[attributeDic objectForKey:key]];
	}
	ret=[ret stringByAppendingString:@"}"];
	[ret retain];
	[pool release];
	return [ret autorelease];
}

@end

NSString* imageUrl(NSString* host, NSString* path){
	NSString* ret=host;
	if([@"http://images.vancl.com/" isEqualToString:host]){
		ret= [NSString stringWithFormat:@"%@%@%@",
              host==nil?@"":host,
              (!stringIsEmpty(host)&&!stringIsEmpty(path))?@"q80/":@"" ,
              path==nil?@"":path];
	}
	return ret;
}





